package com.company.cloud.mall.modules.bus.consumer;

import javax.validation.constraints.NotEmpty;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSON;
import com.company.cloud.common.bean.LoginSimpleUserInfo;
import com.company.cloud.common.mq.redis.client.consumer.ISaasMqConsumer;
import com.company.cloud.common.mq.redis.client.consumer.MQConsumeMessage;
import com.company.cloud.common.mq.redis.client.consumer.MQSaasResult;
import com.company.cloud.common.mq.redis.client.consumer.annotation.MQRedisConsumer;
import com.company.cloud.mall.constant.ShopConstant.PayConfirmWay;
import com.company.cloud.mall.modules.app.controller.req.PayResultReportParam;
import com.company.cloud.mall.modules.app.service.ShopOrderPayService;

import io.swagger.annotations.ApiModelProperty;

@MQRedisConsumer(topic = "Topic:PayNotity:JBH_Pay_01",consumer = "OrderPayNotifyComsumer")
@Service
public class OrderPayNotifyRedisComsumer implements ISaasMqConsumer{

	@Autowired
	private ShopOrderPayService shopOrderPayService;
	
	
	@Override
	public MQSaasResult consume(MQConsumeMessage data) throws Exception {
		System.out.println("+++++++++消费++++++++++");
		System.out.println(JSON.toJSONString(data.getData()));
		
		PayResultReportParam params=new PayResultReportParam();
		params.setSn(data.getData().get("outTradeNo"));
		params.setState(data.getData().get("state"));
		params.setMemo("第三方支付回调");
		params.setThirdState(data.getData().get("resultCode"));
		
		LoginSimpleUserInfo userInfo=new LoginSimpleUserInfo();
		userInfo.setId(-1);
		userInfo.setIp("127.0.0.1");
		shopOrderPayService.payReport(params, PayConfirmWay.ThirdCallback_Confirm, userInfo);
		return MQSaasResult.getSuccess(data.getId());
	}

}
